<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.29
     from type.tnf on 19 December 2010 -->

<TITLE>Type Analysis - Error Reporting in Type Analysis</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000" BACKGROUND="gifs/bg.gif">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0" VALIGN=BOTTOM>
<TR VALIGN=BOTTOM>
<TD WIDTH="160" VALIGN=BOTTOM>
<A HREF="http://eli-project.sourceforge.net/">
<IMG SRC="gifs/elilogo.gif" BORDER=0>
</A>&nbsp;
</TD>
<TD WIDTH="25" VALIGN=BOTTOM>
<img src="gifs/empty.gif" WIDTH=25 HEIGHT=25>
</TD>
<TD ALIGN=LEFT WIDTH="475" VALIGN=BOTTOM>
<A HREF="index.html"><IMG SRC="gifs/title.png" BORDER=0></A>
</TD>
<!-- |DELETE FOR SOURCEFORGE LOGO|
<TD>
<a href="http://sourceforge.net/projects/eli-project">
<img
  src="http://sflogo.sourceforge.net/sflogo.php?group_id=70447&amp;type=13"
  width="120" height="30"
  alt="Get Eli: Translator Construction Made Easy at SourceForge.net.
    Fast, secure and Free Open Source software downloads"/>
</a>
</TD>
|DELETE FOR SOURCEFORGE LOGO| -->
</TR>
</TABLE>

<HR size=1 noshade width=785 align=left>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0>
<TR>
<TD VALIGN=TOP WIDTH="160">
<h4>General Information</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="index.html">Eli: Translator Construction Made Easy</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="gindex_1.html#SEC1">Global Index</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="faq_toc.html" >Frequently Asked Questions</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ee.html" >Typical Eli Usage Errors</a> </td></tr>
</table>

<h4>Tutorials</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="EliRefCard_toc.html">Quick Reference Card</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="novice_toc.html">Guide For new Eli Users</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="news_toc.html">Release Notes of Eli</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="nametutorial_toc.html">Tutorial on Name Analysis</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="typetutorial_toc.html">Tutorial on Type Analysis</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ee.html" >Typical Eli Usage Errors</a> </td></tr>
</table>

<h4>Reference Manuals</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ui_toc.html">User Interface</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="pp_toc.html">Eli products and parameters</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lidoref_toc.html">LIDO Reference Manual</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ee.html" >Typical Eli Usage Errors</a> </td></tr>
</table>

<h4>Libraries</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lib_toc.html">Eli library routines</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="modlib_toc.html">Specification Module Library</a></td></tr>
</table>

<h4>Translation Tasks</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lex_toc.html">Lexical analysis specification</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="syntax_toc.html">Syntactic Analysis Manual</a></td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="comptrees_toc.html">Computation in Trees</a></td></tr>
</table>

<h4>Tools</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="lcl_toc.html">LIGA Control Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="show_toc.html">Debugging Information for LIDO</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="gorto_toc.html">Graphical ORder TOol</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="fw_toc.html">FunnelWeb User's Manual</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="ptg_toc.html">Pattern-based Text Generator</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="deftbl_toc.html">Property Definition Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="oil_toc.html">Operator Identification Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="tp_toc.html">Tree Grammar Specification Language</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="clp_toc.html">Command Line Processing</a> </td></tr>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="cola_toc.html">COLA Options Reference Manual</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="idem_toc.html">Generating Unparsing Code</a> </td></tr>
</table>
<p>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="mon_toc.html">Monitoring a Processor's Execution</a> </td></tr>
</table>

<h4>Administration</h4>

<table BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr valign=top><td><img src="gifs/gelbekugel.gif" WIDTH=7 HEIGHT=7 ALT=" o"> </td><td><a href="sysadmin_toc.html">System Administration Guide</a> </td></tr>
</table>

<HR WIDTH="100%">
<A HREF="mailto:eli-project-users@lists.sourceforge.net">
<IMG SRC="gifs/button_mail.gif" BORDER=0 ALIGN="left"></A>
<A HREF="index.html"><IMG SRC="gifs/home.gif" BORDER=0 ALIGN="right"></A>

</TD>
<TD VALIGN=TOP WIDTH="25"><img src="gifs/empty.gif" WIDTH=25 HEIGHT=25></TD>

<TD VALIGN=TOP WIDTH="600">
<H1>Type Analysis</H1>
<P>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_6.html"><IMG SRC="gifs/prev.gif" ALT="Previous Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_8.html"><IMG SRC="gifs/next.gif" ALT="Next Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_toc.html"><IMG SRC="gifs/up.gif" ALT="Table of Contents" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT="">
<HR size=1 noshade width=600 align=left>
<H1><A NAME="SEC29" HREF="type_toc.html#SEC29">Error Reporting in Type Analysis</A></H1>
<P>
Language-dependent error reporting involves checks based on the
types associated with program constructs by the computations specified
in earlier chapters.
For example, object-oriented languages differ in their requirements for
overriding methods when extending a class definition.
One possibility is
to require that the type of each parameter of the overriding method be
a supertype of the corresponding parameter type of the overridden method,
and that the result type of the overriding method be a subtype of the
result type of the overridden method.
The type analysis modules will establish the complete signatures of both
methods, and the subtype/supertype relation among all type pairs.
Thus only the actual check remains to be written.
<P>
Some errors make it impossible to associate any type with a program
construct, and these are reported by the modules.
Operations are also made available to support detection of incorrect
typing.
<P>
<H2><A NAME="SEC30" HREF="type_toc.html#SEC30">Verifying typed identifier usage</A></H2>
<P>
An applied occurrence of an identifier that purports to represent a
typed entity inherits the <CODE>TypedIdUse</CODE> role.
The value of its <CODE>Type</CODE> attribute should not be <CODE>NoKey</CODE>, and the
identifier itself should not be a type identifier.
Both of these conditions can be checked by inheriting the
<A NAME="IDX176"></A>
<CODE>ChkTypedUseId</CODE> role:
<P>
<A NAME="IDX177"></A>
<PRE>
SYMBOL ExpIdUse INHERITS ChkTypedUseId END;
</PRE>
<P>
If the identifier <SAMP>`id'</SAMP> at an <CODE>ExpIdUse</CODE> node is bound,
but the type is unknown, the <CODE>ChkTypedUseId</CODE> computation will
issue the following report at the source coordinates of <SAMP>`id'</SAMP>
<P>
<PRE>
Must denote a typed object: <SAMP>`id'</SAMP>
</PRE>
<P>
If the identifier <SAMP>`id'</SAMP> at an <CODE>ExpIdUse</CODE> node is a type
identifier, the report would be:
<P>
<PRE>
Type identifier not allowed: <SAMP>`id'</SAMP>
</PRE>
<P>
<H2><A NAME="SEC31" HREF="type_toc.html#SEC31">Verifying type identifier usage</A></H2>
<P>
Both defining and applied occurrences of type identifiers can be checked
for validity.
In each case, the value of the <CODE>Type</CODE> attribute must be a definition
table key whose <CODE>IsType</CODE> property has the value 1.
Two roles are available for this purpose:
<P>
<A NAME="IDX178"></A>
<DL COMPACT>
<DT><CODE>ChkTypeDefDefId</CODE>
<DD>reports an error if the <CODE>Type</CODE> attribute does not refer to a type,
or if the type refers to itself.
<A NAME="IDX179"></A>
<P>
<DT><CODE>ChkTypeDefUseId</CODE>
<DD>reports an error if the <CODE>Type</CODE> attribute does not refer to a type.
</DL>
<P>
<H2><A NAME="SEC32" HREF="type_toc.html#SEC32">Verifying type consistency within an expression</A></H2>
<P>
The <CODE>Expression</CODE> module provides default error reporting associated
with the following roles:
<P>
<A NAME="IDX180"></A>
<DL COMPACT>
<DT><CODE>ExpressionSymbol</CODE>
<DD><DL COMPACT>
<DT>Condition:
<DD><CODE><SAMP>`e'</SAMP>.Type</CODE> is not acceptable as <CODE><SAMP>`e'</SAMP>.Required</CODE>.
<DT>Message:
<DD><SAMP>`Incorrect type for this context'</SAMP>
<A NAME="IDX181"></A>
<A NAME="IDX182"></A>
<A NAME="IDX183"></A>
<DT>Override symbols:
<DD><CODE>ExpMsg</CODE>, <CODE>ExpErr</CODE>, <CODE>ExpError</CODE>
</DL>
<A NAME="IDX184"></A>
<P>
<LI>OperatorSymbol
<DL COMPACT>
<DT>Condition:
<DD>The indication is valid but no operator could be identified.
<DT>Message:
<DD><SAMP>`Incorrect operand type(s) for this operator'</SAMP>
<A NAME="IDX185"></A>
<A NAME="IDX186"></A>
<A NAME="IDX187"></A>
<DT>Override symbols:
<DD><CODE>OprMsg</CODE>, <CODE>OprErr</CODE>, <CODE>OprError</CODE>
</DL>
<A NAME="IDX188"></A>
<P>
<LI>OpndExprListRoot
<DL COMPACT>
<DT>Condition:
<DD>The function requires more arguments than are present.
<DT>Message:
<DD><SAMP>`Too few arguments'</SAMP>
<A NAME="IDX189"></A>
<A NAME="IDX190"></A>
<A NAME="IDX191"></A>
<DT>Override symbols:
<DD><CODE>LstMsg</CODE>, <CODE>LstErr</CODE>, <CODE>LstError</CODE>
</DL>
<A NAME="IDX192"></A>
<P>
<LI>OpndExprListElem
<DL COMPACT>
<DT>Condition:
<DD>The function requires fewer arguments than are present.
<DT>Message:
<DD><SAMP>`Too many arguments'</SAMP>
<A NAME="IDX193"></A>
<A NAME="IDX194"></A>
<A NAME="IDX195"></A>
<DT>Override symbols:
<DD><CODE>ArgMsg</CODE>, <CODE>ArgErr</CODE>, <CODE>ArgError</CODE>
</DL>
</DL>
<P>
This error reporting can be changed by overriding computations for the
<CODE><SAMP>`xxx'</SAMP>Msg</CODE> attribute.
The <CODE><SAMP>`xxx'</SAMP>Err</CODE> attribute has the value 1
if the error condition is met, 0
otherwise.
Thus the overriding computation might be of the form:
<P>
<PRE>
<SAMP>`s'</SAMP>.<SAMP>`xxx'</SAMP>Msg=
  IF(<SAMP>`s'</SAMP>.<SAMP>`xxx'</SAMP>Err,message(ERROR,"My report",0,COORDREF));
</PRE>
<P>
Because <CODE><SAMP>`s'</SAMP>.<SAMP>`xxx'</SAMP>Msg</CODE> is of type <CODE>VOID</CODE>,
you can remove a report completely by
setting <CODE><SAMP>`s'</SAMP>.<SAMP>`xxx'</SAMP>Msg</CODE> to <CODE>"no"</CODE>.
<P>
If you wish to override the message in every context,
write the overriding computation as a symbol computation
in the lower context of the override symbol specified above.
In this case, <SAMP>`xxx'</SAMP> would be <CODE>SYNT</CODE>.
Here is an example, changing the error report for invalid operators in all
contexts:
<P>
<PRE>
SYMBOL OprError COMPUTE
  SYNT.OprMsg=
    IF(SYNT.OprErr,message(ERROR,"Invalid operator",0,COORDREF));
END;
</PRE>
<P>
If you wish to override the message in a few specific contexts,
write the overriding computation as a rule computation
in the lower context of a symbol inheriting the computational role.
In this case, <SAMP>`xxx'</SAMP> would be the symbol on the left-hand side of the
rule.
Here is an example, changing the standrd expression error report to be more
specific for function arguments:
<P>
<PRE>
RULE: Actual ::= Expr COMPUTE
  Actual.ExpMsg=
    IF(Actual.ExpErr,message(ERROR,"Wrong argument type",0,COORDREF));
END;
</PRE>
<P>
<H2><A NAME="SEC33" HREF="type_toc.html#SEC33">Support for context checking</A></H2>
<P>
As noted in the previous section, <CODE>OperatorSymbol</CODE> role computations
normally report an error when an indication is valid but no operator can be
identified.
The <CODE>Expression</CODE> module exports two context-dependent rule
computations for use when an expression node has no children playing that
role.
One computation tests the indication and the other tests the operator:
<P>
<DL COMPACT>
<A NAME="IDX196"></A>
<DT><CODE>BadIndication</CODE>
<DD>Yields 1 if the operator indication supplied by <CODE>Indication</CODE> is
unknown, 0 otherwise.
<P>
<A NAME="IDX197"></A>
<DT><CODE>BadOperator</CODE>
<DD>Yields 1 if the indication is valid but no operator can be selected from
that indication's set, 0 otherwise.
</DL>
<P>
Consider an expression in which a function is applied to arguments
(see  <A HREF="type_6.html#SEC28">Functions as typed entities</A>):
<P>
<A NAME="IDX198"></A>
<A NAME="IDX199"></A>
<A NAME="IDX200"></A>
<A NAME="IDX201"></A>
<A NAME="IDX202"></A>
<A NAME="IDX203"></A>
<PRE>
SYMBOL Expr    INHERITS ExpressionSymbol END;
SYMBOL Actuals INHERITS OpndExprListRoot END;

RULE: Expr ::= Expr '(' Actuals ')' COMPUTE
  ListContext(Expr[1],,Actuals);
  Indication(GetInvoker(Expr[2].Type,NoKey));
  IF(BadIndication,
    message(ERROR,"Invalid function",0,COORDREF));
END;
</PRE>
<P>
Suppose that, because of a programming error, <CODE>Expr[2]</CODE> does not
deliver a function type.
In that case, <CODE>Expr[2].Type</CODE> would not have the <CODE>Invoker</CODE>
property, and <CODE>BadIndication</CODE> would yield 1.
Alternatively, <CODE>Expr[2]</CODE> might deliver a function whose signature
does not match the context.
Because the indication has only a singleton operator set, that operator
will be selected regardless of the context.
Errors will then be reported by the default mechanisms as an incorrect
number of arguments, arguments of incorrect types, or result incorrect for
the context.
<P>
Now consider the array access expression
(see  <A HREF="type_4.html#SEC16">Operators with explicit operands</A>):
<P>
<A NAME="IDX204"></A>
<A NAME="IDX205"></A>
<A NAME="IDX206"></A>
<A NAME="IDX207"></A>
<PRE>
SYMBOL Subscript INHERITS ExpressionSymbol END;

RULE: Expr ::= Expr '[' Subscript ']' COMPUTE
  DyadicContext(Expr[1],,Expr[2],Subscript);
  Indication(indexInd),
  IF(BadOperator,
    message(ERROR,"Invalid array reference",0,COORDREF));
END;
</PRE>
<P>
Suppose that, because of a programming error, <CODE>Expr[2]</CODE> does not
deliver an array type.
In that case, there would be no operator in <CODE>indexInd</CODE>'s operator set
whose left operand was the type returned by <CODE>Expr[2]</CODE> and
<CODE>BadOperator</CODE> would yield 1.
<A NAME="IDX208"></A>
<P>
It is sometimes useful to be able to check whether one type is acceptable
as another outside of the situations covered in the previous section.
Let <SAMP>`from'</SAMP> and <SAMP>`to'</SAMP> be definition table keys representing types.
<CODE>IsCoercible(<SAMP>`from'</SAMP>,<SAMP>`to'</SAMP>)</CODE> yields 1 if a value of type
<SAMP>`from'</SAMP> is acceptable wherever an value of type <SAMP>`to'</SAMP> is required;
it yields 0 otherwise.
<P>
For example, consider a cast involving a reference type in Java.
The cast is known to be correct at compile time if a value is being cast to
its superclass.
If the value is being cast to one of its subclasses, however, a run-time
check is required.
Thus the compiler must accept such a cast <EM>both</EM> when the value is
acceptable as a value of the cast type <EM>and</EM> when a value of the cast
type is acceptable as a value of the type being cast:
<P>
<PRE>
RULE: Expression ::= '(' Expression ')' Expression COMPUTE
  IF(AND(
      NOT(IsCoercible(Expression[2].Type,Expression[3].Type)),
      NOT(IsCoercible(Expression[3].Type,Expression[2].Type))),
    message(ERROR,"Invalid cast",0,COORDREF));
END;
</PRE>
<P>
<HR size=1 noshade width=600 align=left>
<P>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_6.html"><IMG SRC="gifs/prev.gif" ALT="Previous Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_8.html"><IMG SRC="gifs/next.gif" ALT="Next Chapter" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT=""><A HREF="type_toc.html"><IMG SRC="gifs/up.gif" ALT="Table of Contents" BORDER="0"></A>
<IMG SRC="gifs/empty.gif" WIDTH=25 HEIGHT=25 ALT="">
<HR size=1 noshade width=600 align=left>
</TD>
</TR>
</TABLE>

</BODY></HTML>
